home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
rjs.lha
/
RJS
/
Transport
/
src
/
DECnetAddress.C
next >
Wrap
C/C++ Source or Header
|
1991-06-14
|
3KB
|
148 lines
#include "Transport.h"
#include <stdio.h>
#include <osfcn.h>
#include <libc.h>
#include <string.h>
extern "C" {
int dnet_conn(
const char *node,
const char *obj,
int type,
u_char *opt_out,
int opt_outl,
u_char *opt_in,
int *opt_inl
);
struct dn_naddr *dnet_addr(const char *cp);
struct nodeent *getnodebyname(const char *node);
struct objectent *getobjectbyname(const char *name);
const char *dnet_ntoa(struct dn_naddr *add);
const char *dnet_otoa(struct sockaddr_dn *dn);
}
const RJS_Status RJS_DECnetAddress::UnKnownObject("unknown object");
inline int object_number(const char *name)
{
struct objectent *obj=getobjectbyname(name);
if (obj) return obj->o_objnum;
else return -1;
}
const char *RJS_DECnetAddress::hostname() const {
return dnet_ntoa(&address.sdn_add);
}
const char *RJS_DECnetAddress::objname() const {
return dnet_otoa(&address);
}
void RJS_DECnetAddress::dump()
{
cout << "DECnetAddress { " << endl;
cout << " sdn_family : " << address.sdn_family << endl;
cout << " sdn_flags : " << address.sdn_flags << endl;
cout << " sdn_objnum : " << address.sdn_objnum << endl;
cout << " sdn_objnamel : " << address.sdn_objnamel << endl;
cout << " sdn_objname : " << address.sdn_objname << endl;
cout << "}" << endl;
}
RJS_DECnetAddress::RJS_DECnetAddress()
{
ss_set(NoHostGiven);
}
RJS_DECnetAddress::RJS_DECnetAddress(int obj)
{
lookup(obj);
}
RJS_DECnetAddress::RJS_DECnetAddress(const char *obj)
{
lookup(obj);
}
int RJS_DECnetAddress::lookup(int obj)
{
bzero((char *) &address, sizeof(address));
address.sdn_family = RJS_Socket::AfDECnet;
address.sdn_objnum = obj;
ss_set(HostFound);
return 1;
}
int RJS_DECnetAddress::lookup(const char *obj)
{
bzero((char *) &address, sizeof(address));
address.sdn_family = RJS_Socket::AfDECnet;
address.sdn_objnum = object_number(obj);
if (address.sdn_objnum == -1) ss_set(UnKnownObject);
else ss_set(HostFound);
return 1;
}
RJS_DECnetAddress::RJS_DECnetAddress(const char *node,int obj)
{
lookup(node,obj);
}
RJS_DECnetAddress::RJS_DECnetAddress(const char *node,const char *obj)
{
lookup(node,obj);
}
int RJS_DECnetAddress::lookup(const char *node,int obj)
{
struct nodeent *nodep;
struct dn_naddr *node_addr;
bzero((char *) &address , sizeof(address));
address.sdn_family = RJS_Socket::AfDECnet;
address.sdn_objnum = obj;
if ( (node_addr = dnet_addr(node)) == NULL) {
if ((nodep=getnodebyname(node))==NULL) {
ss_set(UnknownHost);
return 0;
} else {
bcopy(nodep->n_addr,address.sdn_nodeaddr,
nodep->n_length);
address.sdn_nodeaddrl = nodep->n_length;
}
} else address.sdn_add = *node_addr;
ss_set(HostFound);
return 1;
}
int RJS_DECnetAddress::lookup(const char *node,const char *obj)
{
struct nodeent *nodep;
struct dn_naddr *node_addr;
bzero((char *) &address , sizeof(address));
address.sdn_family = RJS_Socket::AfDECnet;
address.sdn_objnum = object_number(obj);
if ( (node_addr = dnet_addr(node)) == NULL) {
if ((nodep=getnodebyname(node))==NULL) {
ss_set(UnknownHost);
return 0;
} else {
bcopy(nodep->n_addr,address.sdn_nodeaddr,
nodep->n_length);
address.sdn_nodeaddrl = nodep->n_length;
}
} else address.sdn_add = *node_addr;
if (address.sdn_objnum == -1) ss_set(UnKnownObject);
else ss_set(HostFound);
return 1;
}